package com.util;

import org.lionsoul.ip2region.xdb.Searcher;
import org.springframework.core.io.ClassPathResource;

import java.io.File;

/**
 * @author: cxt
 * @date: 2023/4/8 23:41
 * <p>
 * 根据IP搜索地址
 */
public class SearchAddressByIpUtil {
    public static String searchAddressByIp(String ip) {
        try {
            ClassPathResource resource = new ClassPathResource("/json/ip2region.xdb");
            File file = resource.getFile();
            Searcher searcher = Searcher.newWithFileOnly(file.getAbsolutePath());
            return searcher.search(ip);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return "";
    }
}
